//
//  HLGradientView.m
//  s.
//
//  Created by fanshijian on 2022/9/6.
//  Copyright © 2022 J. All rights reserved.
//

#import "JYGradientView.h"

@implementation JYGradientView

+ (Class)layerClass{
    return CAGradientLayer.class;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        CAGradientLayer *gl = (id)self.layer;
        self.colorsBlock = ^(NSArray * _Nonnull colors) {
            NSMutableArray *gcolors = NSMutableArray.array;
            [colors enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [gcolors addObject:(id)jy_HexColor(obj).CGColor];
            }];
            gl.colors = gcolors;
        };
        self.colorsBlock2 = ^(NSArray * _Nonnull colors) {
            NSMutableArray *gcolors = NSMutableArray.array;
            [colors enumerateObjectsUsingBlock:^(UIColor *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [gcolors addObject:(id)obj.CGColor];
            }];
            gl.colors = gcolors;
        };
        self.pointBlock = ^(CGPoint start, CGPoint end) {
            gl.startPoint = start;
            gl.endPoint   = end;
        };
        gl.locations = @[@(0),@(1.0f)];
    }
    return self;
}

@end
